/*
 * @Description: 
 * @Author: paddies
 * @Date: 2024-06-03 14:56:42
 * @LastEditors: paddies
 * @LastEditTime: 2024-06-03 16:39:11
 * @FilePath: /shared_components/lib/build-tab-list/buildTabList.dart
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_components/build-common/buildCommon.dart';
import 'package:shared_components/build-tab-list/controller.dart';
import 'package:shared_components/init.dart';

class BuildTabList extends StatefulWidget {
  const BuildTabList({super.key});

  @override
  State<BuildTabList> createState() => _BuildTabListState();
}

class _BuildTabListState extends State<BuildTabList> {
  final BuildTabListController controller = Get.put(BuildTabListController());

// 顶部tab
  Widget buildNav() {
    return Container(
        width: double.infinity,
        height: 60,
        // color: Colors.red,
        child: Obx(() => Row(
                children:
                    controller.state.tabList.value.asMap().keys.map((index) {
              var fontColor = const Color(0xff666666);
              if (controller.state.tabIndex.value == index) {
                fontColor = sharedManager.themeColor;
              }
              return Expanded(
                  child: Stack(
                alignment: Alignment.center,
                children: [
                  Container(
                    height: double.infinity,
                    // color: Colors.red,
                    width: 70,
                    child: GestureDetector(
                        onTap: () {
                          controller.changeTab(index: index);
                        },
                        child: Container(
                          alignment: Alignment.center,
                          width: double.infinity,
                          height: double.infinity,
                          color: Colors.transparent,
                          child: Stack(
                            alignment: Alignment.center,
                            children: [
                              Text(
                                showText(controller
                                    .state.tabList.value[index].value["name"]),
                                style: TextStyle(
                                    fontSize: 16,
                                    color: fontColor,
                                    fontWeight: FontWeight.w500),
                              ),
                              if (controller.state.tabIndex.value == index)
                                Container(
                                  margin: const EdgeInsets.only(top: 40),
                                  width: 30,
                                  height: 5,
                                  decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(
                                          Radius.circular(20.0)), //圆角
                                      gradient: LinearGradient(
                                          begin:
                                              Alignment.topLeft, //渐变开始于上面的中间开始
                                          end: Alignment.topRight, //渐变结束于下面的中间
                                          colors: [
                                            sharedManager.themeColor,
                                            sharedManager.themeColor,
                                          ] //开始颜色和结束颜色])),
                                          )),
                                )
                            ],
                          ),
                        )),
                  ),
                  // Visibility(
                  //   visible:
                  //       controller.state.tabList.value[index].value["state"] ==
                  //               "" &&
                  //           controller.state.allCount.value > 0,
                  //   child: Padding(
                  //     padding: EdgeInsets.only(right: 2, top: 8),
                  //     child: Align(
                  //       alignment: Alignment.topRight,
                  //       child: Container(
                  //         width: 30,
                  //         height: 15,
                  //         decoration: BoxDecoration(
                  //           color: Colors.red,
                  //           borderRadius:
                  //               BorderRadius.all(Radius.circular(8.0)), //圆角
                  //         ),
                  //         alignment: Alignment.center,
                  //         child: Text(
                  //           showText(controller.getAllCountName()),
                  //           style: TextStyle(fontSize: 10, color: Colors.white),
                  //         ),
                  //       ),
                  //     ),
                  //   ),
                  // )
                ],
              )

                  //      Container(
                  //   width: double.infinity,
                  //   height: double.infinity,
                  //   child: Text("1"),
                  // )
                  );
            }).toList())));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        // appBar: AppBar(
        //   centerTitle: true,
        //   iconTheme: const IconThemeData(
        //     color: Colors.black, //修改颜色
        //   ),
        //   title: Text(
        //     "",
        //     style: const TextStyle(color: Colors.black),
        //   ),
        //   backgroundColor: Colors.white,
        // ),
        backgroundColor: Colors.white,
        // drawer: MyDrawer(),
        body: Container(
          width: double.infinity,
          height: double.infinity,
          color: Colors.green,
          child: Obx(() => Column(
                children: [
                  Text(showText(controller.state.tabIndex.value)),
                  buildNav()
                ],
              )),
        ));
  }
}
